{extend name="base" /}
{block name="main"}

<style type="text/css">
    .layui-form-checkbox {
        height: 22px;
        line-height: 20px;
        margin-right: 0px;
        padding-right: 20px;
    }

    .layui-form-checkbox i {
        right: 3px;
        width: 20px;
        font-size: 16px;
        top: 2px;
    }
</style>
<div class="fly-panel fly-panel-user">
    <div class="tpt—admin">
        <div class="tpt—btn">
            <a href="{:url('category/add')}"><i class="layui-icon">&#xe61f;</i> 添加分类</a>
        </div>

        <form method="post" class="cl">
            <table width="100%">
                <tr>
                    <th width="5%" align="center">ID</th>
                    <th width="15%" align="center">名称</th>
                    <th width="10%" align="center">类型</th>
                    <th width="10%" align="center">显示</th>
                    <th width="10%" align="center">侧栏</th>
                    <th width="20%" align="center">描述</th>
                    <th width="10%" align="center">时间</th>
                    <th width="10%" align="center">基本操作</th>
                </tr>
                {volist name="tptc" id="vo"}
                <tr>
                    <td align="center">{$vo.id}</td>
                    <td style="padding-left: 20px;">{if condition="$vo['level'] neq 0"}|----------{/if}{$vo.name}</td>
                    <td align="center">
                        {if condition="$vo['type'] eq 1"}默认类型{/if}
                        {if condition="$vo['type'] eq 2"}其他类型{/if}
                    </td>
                    <td align="center">
                        <a change="{$vo.id}" onclick="changeshows(this);" {if condition="$vo['shows'] eq 1"
                           }class="layui-unselect layui-form-switch layui-form-onswitch" {else /}class="layui-unselect
                        layui-form-switch"{/if}>
                        <em>显示</em><i></i>
                        </a>
                    </td>
                    <td align="center">
                        <a change="{$vo.id}" onclick="changesidebar(this);" {if condition="$vo['sidebar'] eq 1"
                           }class="layui-unselect layui-form-switch layui-form-onswitch" {else /}class="layui-unselect
                        layui-form-switch"{/if}>
                        <em>开启</em><i></i>
                        </a>
                    </td>

                    <td class="tpt-rap">{$vo.description}</td>
                    <td align="center">{$vo.time|date="Y-m-d",###}</td>
                    <td align="center">
                        <a class="layui-btn layui-btn-xs layui-btn-warm"
                           href="{:url('category/edit',array('id'=>$vo['id']))}">修改</a> <a
                            class="layui-btn layui-btn-xs layui-btn-danger del_btn" member-id="{$vo.id}" title="删除"
                            nickname="{$vo.name}">删除</a>
                    </td>
                </tr>
                {/volist}
            </table>
        </form>
    </div>
</div>
<script>
    function changeshows(o) {
        var change = $(o).attr("change");
        $.ajax({
            type: "post",
            dataType: "json",
            data: {change: change},
            url: "{:url('category/changeshows')}",
            success: function (data) {
                if (data == 1) {
                    $(o).attr("class", "layui-unselect layui-form-switch");
                } else {
                    $(o).attr("class", "layui-unselect layui-form-switch layui-form-onswitch");
                }
            }
        });
    }

    function changesidebar(o) {
        var change = $(o).attr("change");
        $.ajax({
            type: "post",
            dataType: "json",
            data: {change: change},
            url: "{:url('category/changesidebar')}",
            success: function (data) {
                if (data == 1) {
                    $(o).attr("class", "layui-unselect layui-form-switch");
                } else {
                    $(o).attr("class", "layui-unselect layui-form-switch layui-form-onswitch");
                }
            }
        });
    }
</script>
<script>
    layui.use('form', function () {
        var form = layui.form,
            jq = layui.jquery;

        jq('.del_btn').click(function () {
            var name = jq(this).attr('nickname');
            var id = jq(this).attr('member-id');
            layer.confirm('确定删除【' + name + '】?', function (index) {
                loading = layer.load(2, {
                    shade: [0.2, '#000']
                });
                jq.post('{:url("category/dels")}', {'id': id}, function (data) {
                    if (data.code == 200) {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            location.reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                    }
                });
            });
        });

    })
</script>
{/block}